package com.woniu.service.impl;

import com.woniu.entity.PatientInfo;
import com.woniu.mapper.PatientInfoMapper;
import com.woniu.service.PatientService;
import com.woniu.utils.ResponseEnum;
import com.woniu.utils.ResponseUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PatientServiceImpl implements PatientService {
    @Resource
    private PatientInfoMapper patientInfoMapper;
    @Override
    public ResponseUtil addPatient(PatientInfo patientInfo) {
        int i = patientInfoMapper.insertSelective(patientInfo);
        return i>0?ResponseUtil.get(ResponseEnum.OK)
                :ResponseUtil.get(ResponseEnum.FAIL);
    }
    @Override
    public ResponseUtil findById(Integer id) {
        PatientInfo patientInfo = patientInfoMapper.findById(id);

        return patientInfo!=null?ResponseUtil.get(ResponseEnum.OK,patientInfo)
                :ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil findAll() {
        List<PatientInfo> all = patientInfoMapper.findAll();
        return !all.isEmpty()?ResponseUtil.get(ResponseEnum.OK,all)
                :ResponseUtil.get(ResponseEnum.FAIL);
    }
}
